var t = getApp();

Page({
    data: {
        server: t.server,
        serverUrl: t.serverUrl,
        cates: [],
        currCate: 0
    },
    onLoad: function(e) {
        var a = this;
        t.request({
            url: t.server + "/productApi/getFullSceneCat",
            method: "POST",
            data: {
                token: t.token,
                page_size: 999,
                cur_page: 1
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                if (a.setData({
                    cates: t.data.result.data
                }), a.data.cates.length > 0) for (var e = 0; e < a.data.cates.length; e++) a.loadCate(e);
                a.active(0);
            }
        });
    },
    swichCate: function(t) {
        this.active(t.currentTarget.dataset.index);
    },
    switchTab: function(t) {
        this.active(t.detail.current);
    },
    active: function(t) {
        this.setData({
            currCate: t
        });
    },
    loadCate: function(t) {
        for (var e = this.data.cates[t], a = 0; a < e.children.length; a++) this.loadPrds(t, a);
    },
    loadPrds: function(e, a) {
        var r = this.data.cates[e].children[a], c = this;
        t.request({
            url: t.server + "/productApi/getFullSceneCatInfo",
            method: "POST",
            data: {
                token: t.token,
                page_size: 999,
                cur_page: 1,
                cid: r.id
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var r = {};
                r["cates[" + e + "].children[" + a + "].prds"] = t.data.result.list, c.setData(r);
            }
        });
    },
    toDetail: function(t) {
        var e = t.currentTarget.dataset.cateindex, a = t.currentTarget.dataset.subcateindex, r = t.currentTarget.dataset.index, c = this.data.cates[e], s = c.children[a], i = s.prds[r];
        wx.navigateTo({
            url: "/pages/360/detail/detail?id=" + i.id + "&subCateId=" + s.id + "&cateId=" + c.id
        });
    },
    onShareAppMessage: function() {}
});